package com.wyj.user.controller;

import com.wyj.response.ApiResult;
import com.wyj.user.api.IUser4AuthApi;
import com.wyj.user.entity.vo.SimpleUserVO;
import com.wyj.user.service.UserAuthApiImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;

/**
 * TODO: 用户控制层
 *
 * @author wuyijie
 * @date 2022/2/9 6:24 PM
 */
@RestController
@RequestMapping(value = "/auth")
@RefreshScope
@Slf4j
public class UserAuthController implements IUser4AuthApi {
    @Value("${user.name}")
    private String name;

    private final UserAuthApiImpl userAuthApi;

    public UserAuthController(UserAuthApiImpl userAuthApi) {
        this.userAuthApi = userAuthApi;
    }

    @RequestMapping(value = "test1", method = RequestMethod.GET)
    public String test1() {
        return name;
    }


    @Override
    public ApiResult<SimpleUserVO> register(String email, String password, String code) {
        return userAuthApi.register(email, password, code);
    }


    @Override
    public ApiResult<SimpleUserVO> login(String email, String password, HttpServletRequest request, HttpServletResponse response) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
        return userAuthApi.login(email, password, request, response);
    }


    @Override
    public ApiResult<Boolean> verificationCode(String identification) {
        return userAuthApi.getVerificationCode(identification);
    }


}
